using System;
using System.Collections.ObjectModel;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Systepic.Projects;

/// <summary>
/// Summary description for ProjectsHelper
/// </summary>
public class ProjectsHelper
{
	public static MembershipUserCollection FindUsersByUsername(string usernameToMatch)
	{
		if (usernameToMatch == null)
			return null;

		return Membership.FindUsersByName(usernameToMatch);
	}

	public static bool DeleteUser(string username)
	{
		if (username == null)
			return false;

		return Membership.DeleteUser(username);
	}

	public static Project GetProjectById(int id)
	{
		if (!ProjectsService.IsInitialized)
			return null;

		lock (ProjectsService.Provider)
		{
			return ProjectsService.Provider.GetProjectById(id);
		}
	}

	public static bool DeleteProject(Project p)
	{
		if (!ProjectsService.IsInitialized)
			return false;

		lock (ProjectsService.Provider)
		{
			return ProjectsService.Provider.DeleteProject(p);
		}
	}

	public static bool AddProject(Project p)
	{
		if (!ProjectsService.IsInitialized)
			return false;

		lock (ProjectsService.Provider)
		{
			CreateProjectStatus s;
			return (ProjectsService.Provider.CreateProject(p, out s) != null) ? true : false;
		}
	}

	public static Collection<Project> GetUserProjects(string username)
	{
		if (!ProjectsService.IsInitialized)
			return null;

		lock (ProjectsService.Provider)
		{
			return ProjectsService.Provider.GetProjectsForUser(username);
		}
	}

	public static Collection<Project> GetAllProjects()
	{
		if (!ProjectsService.IsInitialized)
			return null;

		lock (ProjectsService.Provider)
		{
			return ProjectsService.Provider.GetAllProjects();
		}
	}

	public static Collection<ProjectsUser> GetUsers()
	{
		if (!ProjectsService.IsInitialized)
			return null;

		lock (ProjectsService.Provider)
		{
			return ProjectsService.Provider.GetUsers();
		}
	}
}
